#include "common.h"

int longestOnes(vector<int>& nums, int k)
{
	int n = 0;
	int left = 0;
	int right = 0;
	int len = nums.size();
	int ans = 0;
	while (right < len)
	{
		if (nums[right] == 0) n++;
		right++;
		while (n > k)
		{
			if (nums[left] == 0) n--;
			left++;
		}
		ans = max(ans, right - left);
	}
	return ans;
}